package com.example.shop.mapper;

import com.example.shop.common.OrderStatus;
import com.example.shop.entity.Order;
import jakarta.websocket.server.PathParam;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author qwer3
 * @version 1.0.0
 * @create 2025/11/2 15:55
 */
@Mapper
public interface OrderMapper {
    @Insert("""
INSERT INTO mi_order (order_id, user_id, address_id, total_price, status,
                      create_time, update_time, operator_id, is_delete) 
VALUES (#{orderId}, #{userId}, #{addressId}, #{totalPrice}, #{status}, now(), now(), null, 0);
""")
    void createOrder(Order order);


    @Select("""
select * from mi_order where user_id = #{userId} order by create_time desc
""")
    List<Order> getOrderByUserId(String userId);

    @Select("""
select * from mi_order where order_id = #{orderId}
""")
    Order getOrderByOrderId(String orderId);

    @Update("""
update mi_order set status = #{newStatus}, update_time = now() where order_id = #{orderId}
""")
    void modifyOrderStatus(@PathParam("orderId") String orderId,
                           @PathParam("newStatus") OrderStatus newStatus);
}
